package com.efast.dmom.mgmt.controller.les.pda;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import io.swagger.annotations.ApiOperation;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.entity.les.TwQualityTaskDetail;
import com.efast.dmom.mgmt.entity.les.TwQualityTaskHeader;
import com.efast.dmom.mgmt.service.les.TwQualityTaskDetailService;
import com.efast.dmom.mgmt.service.les.TwQualityTaskHeaderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 质检任务头表 前端控制器
 * </p>
 *
 * @author ChenLiPeng
 * @since 2018-05-27
 */
@Controller
@RequestMapping("/twQualityTaskHeader")
@Api(description = "质检任务头表")
public class TwQualityTaskHeaderController {

	private final TwQualityTaskDetailService twQualityTaskDetailService;
	private final TwQualityTaskHeaderService twQualityTaskHeaderService;

	@Autowired
	public TwQualityTaskHeaderController(TwQualityTaskDetailService twQualityTaskDetailService,
			TwQualityTaskHeaderService twQualityTaskHeaderService) {
		this.twQualityTaskDetailService = twQualityTaskDetailService;
		this.twQualityTaskHeaderService = twQualityTaskHeaderService;
	}

	@ApiOperation(value = "【质检关闭】")
	@RequestMapping(value = "/close", method = RequestMethod.POST)
	public @ResponseBody ResultBean close(@RequestBody TwQualityTaskHeader twQualityTaskHeader) {
		ResultBean result = new ResultBean(true, "'");
		// 质检任务状态 : 0-新单 1-质检通过 2-质检不通过 3-关闭
		twQualityTaskHeader.setQualityStatus("3");
		twQualityTaskHeaderService.updateById(twQualityTaskHeader);
		TwQualityTaskDetail twQualityTaskDetail = new TwQualityTaskDetail();
		twQualityTaskDetail.setQualityStatus("3");
		EntityWrapper<TwQualityTaskDetail> wrapper = new EntityWrapper(twQualityTaskDetail);
		wrapper.where("tw_quality_task_header_id", twQualityTaskHeader.getTwQualityTaskHeaderId());
		twQualityTaskDetailService.update(twQualityTaskDetail, wrapper);
		result.setMessage("成功");
		return result;
	}

}
